package 二叉树相关问题;

public class 跟到叶子节点数字之和 {
    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(5);
        System.out.println(sumNumbers(treeNode));
    }

     //Definition for a binary tree node.
      public static class TreeNode {
         public int var;
         int val;
         TreeNode left;
         TreeNode right;
         TreeNode(int x)
         { val = x; }
      }
    public static int sumNumbers(TreeNode root) {
       return sumNumber(root, 0);
    }
    public static int sumNumber(TreeNode root,int i){
          if (root==null){
              return 0;
          }
          int temp=i*10+root.var;
          if (root.left==null && root.right==null){
              return temp;
          }
          return sumNumber(root.left,temp)+sumNumber(root.right,temp);


    }
}
